package com.quickthumb.game;

import java.util.ArrayList;

public abstract class Rat implements UpdateAndDraw {

	public int counter;
	protected int position, lifetime;
	protected boolean dead;

	public static ArrayList<Rat> rats = new ArrayList<Rat>();
	static {
		rats.add(new RatLab());
		rats.add(new RatAngle());
		rats.add(new RatTheif());
		rats.add(new RatDragon());
		rats.add(new RatShadow());
		rats.add(new RatKing());
	}

	@Override
	public void update() {
		counter++;
		if (counter >= lifetime) {
			destroy();
			Screen.bucket.remove(this);
		}
	}

	public abstract void kill();

	public abstract void hunt();

	public abstract int percent();
	public abstract  int getPower() ;
	
	public int findEmptyHole() {
		int out = 0;
		while (true) {
			out = Screen.random.nextInt(Screen.HOLES_H * Screen.HOLES_W);
			int i;
			for (i = 0; i < Screen.bucket.size(); i++)
				if (Screen.bucket.get(i).position == out)
					break;
			if (i == Screen.bucket.size())
				return out;
		}
	}

	public Rat show() {
		init();
		position = findEmptyHole();
		Screen.bucket.add(this);
		dead = false;
		return this;
	}

	public abstract void hide();

	public boolean isAlive() {
		return counter >= 0 && !dead;
	}

	@Override
	public String toString() {
		return " " + percent() + " ";
	}

}
